package com.jt.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 如果yml和properties有重名的属性key,则以yml为准
 * 所以属性最好不要重复
 */

@RestController
@PropertySource("classpath:/properties/redis.properties")
public class RedisController{
    //从yml中取值
    @Value("${redis.host}")
    private String host;    //=127.0.0.1
    @Value("${redis.port}")
    private int port;       //=6379

    //从properties中取值
    @Value("${redis2.host}")
    private String host2;    //=127.0.0.1
    @Value("${redis2.port}")
    private int port2;       //=7000

    @RequestMapping("getNode")
    public String getNode(){
        return "yml方式"+host+":"+port+"<br>"+
                "properties方式"+host2+":"+port2;
    }
}
